<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/picker.css" />
		<link rel="stylesheet" href="../css/poppicker.css" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" type="text/css" href="../css/datepicker3.css" />
		<link rel="stylesheet" href="../css/member.css" />
		<style type="text/css">
			/* demo */
			
			.demo {
				width: 500px;
				margin: 40px auto;
			}
			
			.demo span {
				display: inline-block;
				width: 240px;
			}
			
			.demo span input {
				padding: 3px;
				width: 120px;
				font-size: 12px;
				font-family: Arial, Helvetica, sans-serif;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a id="shan" class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">服务发布</h1>
			<!--//<button class="mui-pull-right edit" id="btn" style="background-color: #ff7831;border: 0px;color: #efecec; font-size: 16px;">保存</button>-->
		</header>
		<div class="mui-content address_content">
			<form class="mui-input-group">
				<div class="mui-input-row ">
					<label>名称：</label>
					<input type="text" id="title" class="mui-input-group">
				</div>
				<div class="mui-input-row">
					<label>详情：</label>
					<input type="text" id="content" class="mui-input-group">
				</div>
				<div class="mui-input-row">
					<label>售价：</label>
					<input type="text" id="price1" class="mui-input-group">
				</div>
				<div class="mui-input-row">
					<label>会员价：</label>
					<input type="text" id="price2" class="mui-input-group">
				</div>
				<div class="mui-input-row">
					<label>简介：</label>
					<textarea rows="3" cols="20" id="info" class="mui-text-center"></textarea>
				</div>
				<div class="mui-input-row">
					<label>地址：</label>
					<input type="text" id="address" class="mui-input-group">
				</div>
				<div class="mui-input-row">
						<label>开始时间：</label>
						<input type="text" value="" placeholder="请输入开始时间" id="add_time" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:ss')"/>
				</div>
				<div class="mui-input-row">
					<label>结束时间：</label>
					<input type="text" value="" placeholder="请输入结束时间" id="end_time" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:ss')"/>
				</div>
			</form>
			<div class="address_mor clearfix">
				<label class="col-sm-3 control-label">图文详情：</label>
				<strong>默认第一张主图</strong>
				<form class="mui-input-group gerenzl_group">
					<div class="gerenzl_top img-click">
						<div class="actions">
							<button class="file-btn" style="width: 60%; height: 30px;">
				               <span style="font-size: 12px;width: 60%;">上传图片</span>
				                <input type="file" id="upload" value="选择图片文件" multiple/>
				           </button>
							<hr>
							<div id="img_list" class="img_list">

							</div>
						</div>

					</div>

				</form>

				<div class="gerzl_btn" id="btn" onclick="func1()">
					<a href="#">发布</a>
				</div>
			</div>
			<input type="hidden" id='order_ids'>
			<script type="text/javascript" src="../js/jquery.min.js"></script>
			<script type="text/javascript" src="../js/bootstrap-datepicker.js"></script>
			<script src="../js/layer/layer.min.js"></script>
			<script src="../js/mui.min.js"></script>
			<script src="../js/castapp.js"></script>
			<script src="../js/picker.js"></script>
			<script src="../js/poppicker.js"></script>
			<script src="../js/city.data-3.js"></script>
			<script src="../js/app.js"></script>
			<script type="text/javascript" src="../js/adddate.js"></script>
			<script src="../js/ueditor/ueditor.config.js" type="text/javascript"></script>
			<script src="../js/ueditor/ueditor.all.js" type="text/javascript"></script>

			<script>
				//编辑器
				var member = JSON.parse(localStorage.getItem('member'));
				$(function() {
					dlpd();

					$(".datetimepicker").datepicker({
						language: "zh-CN",
						autoclose: true, //选中之后自动隐藏日期选择框
						clearBtn: true, //清除按钮
						todayBtn: true, //今日按钮
						format: "yyyy-mm-dd" //日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
					});
					$('#upload').on('change', function() {
						readFile(this, "thumb", 1, 10);
					});

					//获取分类
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/get_type",
						data: {},
						dataType: 'jsonp',
						success: function(data) {
							var type = data.list;
							for(var i = 0; i < type.length; i++) {
								$('#type').append('<option value=' + type[i]['id'] + '>' + type[i]['typename'] + '</option>');
							}

						},

					});

				});

				$("#shan").click(function() {
					location.href = "spedit.html";
				});
				//获取传过来的图片
				function func1() {
					var x = document.getElementsByName("pic_d");
					var pic_d = "";
					var images = "";
					for(var i = 0; i < x.length; i++) {
						if(i == 0) {
							images += x[i].value;
							pic_d += x[i].value;
						} else {
							pic_d += '@' + x[i].value;
						}

					}

					if($("#title").val() == '') {
						layer.msg('名称不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($("#content").val() == '') {
						layer.msg('请填写详情', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#price1').val() == '') {
						layer.msg('售价不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#price2').val() == '') {
						layer.msg('会员价不能为空', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#add_time').val() == '') {
						layer.msg('请填写时间', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if($('#address').val() == '') {
						layer.msg('请填写地址', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					if(pic_d == "") {
						layer.msg('请上传图片', { icon: 1, time: 1500, shade: 0.1 })
						return false;
					}
					$.ajax({
						type: "post",
						url: APP.api_url + "goods/cre_serve",
						data: {
							id: member['id'],
							title: $('#title').val(),
							content: $("#content").val(),
							price1: $('#price1').val(),
							price2: $('#price2').val(),
							address: $("#address").val(),
							add_time: $('#add_time').val(),
							end_time: $('#end_time').val(),
							pic: pic_d,
							images: images,
							info: $('#info').val()
						},
						dataType: 'jsonp',
						success: function(data) {
							layer.msg(data.msg, { icon: 1, time: 1500, shade: 0.1 }, function(index) {
								window.location.href = "../serve/index.html";
							});
						},

					});

				}
			</script>